package cn.topevery.garden.dal.util;

import hw.topevery.framework.GeometryHelper;
import hw.topevery.framework.dto.PointDto;

import java.util.List;

/**
 * @author ：peng.tian
 * @date ：Created in 2021/8/24 10:18
 * @description：空间数据工具拓展
 */
public class GeometryExtHelper extends GeometryHelper {

    public static String PointToWkt(List<PointDto> list) {
        StringBuilder wellKnownText = new StringBuilder("POINT (");
        Boolean isMultiple = list.size() > 1 ? true : false;
        if (isMultiple) {
            wellKnownText = new StringBuilder("MULTIPOINT (");
        }

        for (int i=0;i<list.size();i++){
            PointDto pointDto =list.get(i);
            wellKnownText.append(String.format("%f %f", pointDto.getLng(), pointDto.getLat()));
            if(i+1<list.size()){
                wellKnownText.append(",");
            }
        }

        wellKnownText.append(")");
        return wellKnownText.toString();
    }

    public static String LineToWkt(List<List<PointDto>> mapRangesPoints) {
        StringBuilder wellKnownText = new StringBuilder("MULTILINESTRING (");
//        if (GeometryTypeEnum.PLANE == geometryTypeEnum) {
//            wellKnownText = new StringBuilder("LINESTRING (");
//        }
//
//        Iterator var3 = list.iterator();
//
//        while(var3.hasNext()) {
//            List<PointDto> pointDtos = (List)var3.next();
//            wellKnownText.append("(");
//            if (GeometryTypeEnum.PLANE == geometryTypeEnum) {
//                wellKnownText.append("(");
//            }
//
//            Iterator var5 = pointDtos.iterator();
//
//            while(var5.hasNext()) {
//                PointDto pointDto = (PointDto)var5.next();
//                wellKnownText.append(String.format("%f %f,", pointDto.getLng(), pointDto.getLat()));
//            }
//
//            if (GeometryTypeEnum.PLANE == geometryTypeEnum) {
//                wellKnownText.append(String.format("%f %f", ((PointDto)pointDtos.get(0)).getLng(), ((PointDto)pointDtos.get(0)).getLat()));
//            } else if (wellKnownText.length() > 18) {
//                wellKnownText = new StringBuilder(wellKnownText.substring(0, wellKnownText.length() - 1));
//            }
//
//            if (GeometryTypeEnum.PLANE == geometryTypeEnum) {
//                wellKnownText.append(")),");
//            } else {
//                wellKnownText.append("),");
//            }
//        }
//
//        if (wellKnownText.length() > 18) {
//            wellKnownText = new StringBuilder(wellKnownText.substring(0, wellKnownText.length() - 1));
//        }
//
//        wellKnownText.append(")");
        return wellKnownText.toString();
    }
}
